home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18304 < prev    next >
Encoding:
Text File  |  1996-08-05  |  823 b   |  41 lines

  1. Path: news.tp.ac.com!news
  2. From: Asgeir Olafsson <olafsson@cstar.ac.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: A question of privacy
  5. Date: Fri, 19 Apr 1996 15:18:28 -0500
  6. Organization: Andersen Consulting
  7. Message-ID: <3177F514.544E@cstar.ac.com>
  8. NNTP-Posting-Host: cstar51060.tp.ac
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0 (WinNT; I)
  13.  
  14. Should the following work according to the ANSI C++
  15. standard draft?
  16.  
  17. // Compiles fine under VC++ 4.0
  18. class A {
  19. private:
  20.     A() {}
  21. };
  22.  
  23. class B {
  24. public:
  25.     A &f() { return A();} // No complaints about privacy
  26. };
  27.  
  28. void g()
  29. {
  30.     B b;
  31.     A a = b.f();
  32. }
  33.  
  34.  
  35. I suspect what is happening, is that a temporary object
  36. is being created, so if this is legal the object could be
  37. deleted as soon as "a" goes out of scope?
  38.  
  39. Regards,
  40. 'Asgeir.
  41.